//
//  AreaCodeModel.swift
//  MuYing
//
//  Created by tbb on 2020/1/14.
//  Copyright © 2020 TBB. All rights reserved.
//

import UIKit

class AreaCodeModel: NSObject,Codable {
    @objc var en: String?
    @objc var zh: String?
    @objc var locale: String?
    @objc var code: String?
    
    @objc public class func getAreaCode (_ areaCodeBlock: ([AreaCodeModel]) -> ()) {
//        let codeMode = AreaCodeModel();
        let path = Bundle.main.url(forResource: "AreaCode", withExtension: "txt");
        let data = try! Data(contentsOf: path!)
        let jsonString = String(data: data, encoding: .utf8)
        let jsonData:Data = (jsonString?.data(using: .utf8)! ?? nil)!;
        
        let array:[NSDictionary] = try! JSONSerialization.jsonObject(with: jsonData, options: .mutableContainers) as! [NSDictionary]
        var codeModelArr = [AreaCodeModel]();
        for dict in array {
            let codeModel = AreaCodeModel();
            codeModel.en = dict["en"] as? String;
            codeModel.zh = dict["zh"] as? String;
            codeModel.locale = dict["locale"] as? String;
            let code:Int = dict["code"] as? Int ?? 0;
            codeModel.code = String(format:"%zd",code)
            codeModelArr.append(codeModel);
        }
        areaCodeBlock(codeModelArr);
    }
}
    

